import pandas as pd

# 1. 创建Excel模板（如果尚未存在）
def create_excel_template():
    data = {
        "config": ["1node-4proc", "2node-8proc", "4node-16proc"],  # 配置字符串
        "o": [42.1, 87.9, 15.9],         # 整数结果
        "l": [3.14, 1.62, 2.72]    # 浮点数结果
    }
    df = pd.DataFrame(data)
    df.to_excel("F:\PostGraduate\Point-to-Point-DATA\deal-data-code\C-lop-Prediction\static\dataset.xlsx", index=False)
    print("Excel模板已创建：dataset.xlsx")

# 2. 从Excel读取数据
def read_excel_c_and_l_data(clop_excel_path):
    #df = pd.read_excel("F:\PostGraduate\Point-to-Point-DATA\deal-data-code\C-lop-Prediction\static\c-lop-o-and-l.xlsx")
    # df = pd.read_excel("F:\PostGraduate\Point-to-Point-DATA\deal-data-code\C-lop-Prediction\static\dataset.xlsx")
    df = pd.read_excel(clop_excel_path)

    
    # 转换为字典（便于通过config快速查找对应的o和l值）
    config_map = {}
    for _, row in df.iterrows():
        config_map[row["config"]] = {
            "o": float(row["o"]),
            "l": float(row["l"])
        }

    return df, config_map

# 使用示例
if __name__ == "__main__":
    # 首次运行创建模板（后续可注释掉）
    # create_excel_template()
    
    # 读取数据
    df, config_map = read_excel_c_and_l_data()
    
    # 打印结果
    print("\n从Excel读取的DataFrame:")
    print(df)
    
    print("\n解析后的配置映射:")
    for config, values in config_map.items():
        print(f"配置 {config}: o={values['o']}, l={values['l']}")
    
    # 示例：如何快速查找特定配置的值
    test_config = "2node-8proc"
    if test_config in config_map:
        print(f"\n快速查找 {test_config} 的值: o={config_map[test_config]['o']}, l={config_map[test_config]['l']}")